{{extend '../_layouts/home.html'}}

{{block 'title'}}{{'多人博客 - 首页'}}{{/block}}

{{block 'body'}}
<section class="container">
  {{include '../_partials/settings-nav.html'}}
  <div class="col-md-5">
    <div class="subhead">
      <h2>修改密码</h2>
    </div>
    <hr>
    <form id="admin_form">
      <div class="form-group">
        <label for="password">当前密码</label>
        <input type="password" class="form-control" id="password" name="password" placeholder="">
      </div>
      <div class="form-group">
        <label for="newPassword">新的密码</label>
        <input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="">
      </div>
      <div class="form-group">
        <label for="qrPassword">确认密码</label>
        <input type="password" class="form-control" id="qrPassword" name="qrPassword" placeholder="">
      </div>
      <button type="submit" class="btn btn-success">保存</button>
    </form>
    <div class="subhead">
      <h2>注销账号</h2>
      <hr>
    </div>
    <div>
      <p>一旦注销，不可找回，请谨慎操作</p>
      <button class="btn btn-danger">删除</button>
    </div>
    <hr>
  </div>
</section>
<script src="/node_modules/jquery/dist/jquery.js"></script>
<script>
    $('#admin_form').on('submit', function (e) {
      e.preventDefault()
      var formData = $(this).serialize()
      console.log(formData)
      $.ajax({
        url: '/settings/admin',
        type: 'post',
        data: formData,
        dataType: 'json',
        success: function (data) {
          var err_code = data.err_code
          if (err_code === 0) {
            // window.alert('注册成功！')
            // 服务端重定向针对异步请求无效
            window.location.href = '/'
          } else {
            window.alert(data.message)
            window.location.reload()
          }
        }
      })
    })
  </script>
{{/block}}
